package com.google.code.irouter.portal.client.dashboard.main.center.managers.relation;

import com.google.code.irouter.portal.client.dashboard.main.center.managers.relation.browser.Editor;
import com.google.code.irouter.portal.client.dashboard.main.center.managers.relation.browser.Monitor;
import com.google.code.irouter.portal.client.dashboard.main.center.managers.relation.browser.editor.Detail;
import com.google.code.irouter.portal.client.dashboard.main.center.managers.relation.browser.editor.detail.Consumer;
import com.google.code.irouter.portal.client.dashboard.main.center.managers.relation.browser.editor.detail.Guide;
import com.google.code.irouter.portal.client.dashboard.main.center.managers.relation.browser.editor.detail.command.Name;
import com.gwtext.client.core.Ext;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.layout.CardLayout;

public final class Browser extends Panel {

	public Browser() {
		super();
		this.setId(Browser.class.getName());
		
		this.setBorder(false);
		this.setLayout(new CardLayout());
		this.add(new Monitor());
		this.add(new Editor());
		this.setActiveItem(0);
	}
	
	public void add() {
		this.setActiveItem(1);
		((Editor) Ext.getCmp(Editor.class.getName())).reset();
		((Detail) Ext.getCmp(Detail.class.getName())).setActiveTab(0);
		((Detail) Ext.getCmp(Detail.class.getName())).setRelationshipId(null);
	}
	
	public void load(String id, String name) {
		this.setActiveItem(1);
		((Editor) Ext.getCmp(Editor.class.getName())).reset();
		((Detail) Ext.getCmp(Detail.class.getName())).setActiveTab(0);
		((Detail) Ext.getCmp(Detail.class.getName())).setGlobalDisable();
		((Detail) Ext.getCmp(Detail.class.getName())).setRelationshipId(id);
		((Name) Ext.getCmp(Name.class.getName())).setValue(name);
		((Guide) Ext.getCmp(Guide.class.getName())).getTarget().load(id);
		((Consumer) Ext.getCmp(Consumer.class.getName())).getTarget().load(id);
	}

}
